<template>
  <div>
    <el-tabs
      :tab-position="tabPosition"
      v-model="activeName"
      @tab-click="tabclick"
      class="role-view"
    >
      <el-tab-pane
        :label="item.name"
        :name="String(item.id)"
        v-for="(item,index) in rolelist"
        :key="index"
      >
        <div class="titbox">
          <div></div>
          <div style="margin-right:10px">
            <el-button type="primary" v-if="showbtn7" @click="invitemembers">添加成员</el-button>
            <el-button type="primary" v-if="showbtn4" @click="editrole">编辑角色</el-button>
            <!-- <el-button type="danger" v-if="showbtn5" @click="del">删除角色</el-button> -->
          </div>
        </div>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="avatar" label="头像">
            <template slot-scope="scope">
              <img
                :src="scope.row.avatar"
                :fit="fit"
                style="width:28px;height:28px;border-radius:4px;"
                alt
              />
            </template>
          </el-table-column>
          <el-table-column prop="admin_name" label="账号"></el-table-column>
          <!-- <el-table-column prop="admin_name" label="密码"></el-table-column> -->
          <!-- <el-table-column prop="sex" label="性别"></el-table-column> -->
          <el-table-column prop="store" label="管理门店" show-overflow-tooltip>
            <!-- <template slot-scope="scope">
              <span v-for="item in scope.row.store" :key="item">{{item.store_name+' '}}</span>
            </template>-->
            <template slot-scope="scope">
              <span
                size="mini"
                style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"
                v-for="(item,index) in scope.row.store"
                :key="index"
              >{{scope.row.store.length==1?item.store_name:item.store_name+","}}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="status" label="状态"></el-table-column> -->
          <el-table-column label="操作" v-if="item.id!=1">
            <template slot-scope="scope">
              <el-button
                v-if="showbtn18"
                @click.native.prevent="editadmin(scope.row)"
                type="text"
              >编辑</el-button>
              <el-button
                v-if="showbtn19"
                @click.native.prevent="deladmin(scope.$index, tableData)"
                type="text"
              >删除</el-button>
              <el-button
                v-if="showbtn20"
                @click.native.prevent="changestores(scope.row)"
                type="text"
              >更换授权门店</el-button>
              <el-button
                v-if="showbtn21"
                @click.native.prevent="transferroles(scope.$index, tableData)"
                type="text"
              >转移成员角色</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="width:100%;text-align:center;margin:50px auto;">
          <el-pagination
            background
            :page-sizes="[10, 20, 50, 100]"
            :page-size="10"
            layout="total,prev, sizes, pager, next, jumper"
            :total="totle"
            @size-change="handleSizeChange"
            @current-change="fenyeBtn"
          ></el-pagination>
        </div>
      </el-tab-pane>
      <!-- <el-tab-pane label="超级管理员" name="33">
        <div class="titbox">
          <div></div>
          <div style="margin-right:10px">
            <el-button type="primary" class="platRole_7" @click="invitemembers">邀请成员</el-button>
            <el-button type="primary" class="platRole_4" @click="editrole">编辑角色</el-button>
            <el-button type="danger" class="platRole_5" @click="del">删除角色</el-button>
          </div>
        </div>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="avatar" label="头像">
            <template slot-scope="scope">
              <img :src="scope.row.avatar" style="width:28px;height:28px;border-radius:4px;" alt />
            </template>
          </el-table-column>
          <el-table-column prop="admin_name" label="昵称"></el-table-column>
          <el-table-column prop="sex" label="性别"></el-table-column>
          <el-table-column prop="store" label="管理门店">
            <template slot-scope="scope">
              <span v-for="item in scope.row.store" :key="item">{{item.store_name}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态"></el-table-column>
        </el-table>
      </el-tab-pane>-->
      <!-- <el-tab-pane label="管理员" name="38">
        <div class="titbox">
          <div></div>
          <div style="margin-right:10px">
            <el-button type="primary" class="platRole_15" @click="invitemembers">邀请成员</el-button>
            <el-button type="primary" class="platRole_14" @click="editrole">编辑角色</el-button>
            <el-button type="danger" @click="del">删除角色</el-button>
          </div>
        </div>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="avart" label="头像">
            <template slot-scope="scope">
              <img :src="scope.row.avart" style="width:28px;height:28px;border-radius:4px;" alt />
            </template>
          </el-table-column>
          <el-table-column prop="admin_name" label="昵称"></el-table-column>
          <el-table-column prop="sex" label="性别"></el-table-column>
          <el-table-column prop="store" label="管理门店">
            <template slot-scope="scope">
              <span v-for="item in scope.row.store" :key="item">{{item.store_name}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                class="platRole_8"
                @click.native.prevent="deladmin(scope.$index, tableData)"
                type="text"
                size="small"
              >删除</el-button>
              <el-button
                @click.native.prevent="changestores(scope.$index, tableData)"
                type="text"
                size="mini"
              >更换授权门店</el-button>
              <el-button
                @click.native.prevent="transferroles(scope.$index, tableData)"
                type="text"
                size="mini"
              >转移成员角色</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>-->
      <!-- <el-tab-pane label="运营人员" name="99">
        <div class="titbox">
          <div></div>
          <div style="margin-right:10px">
            <el-button type="primary">邀请成员</el-button>
            <el-button type="primary">编辑角色</el-button>
            <el-button type="danger">删除角色</el-button>
          </div>
        </div>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="avart" label="头像">
            <template slot-scope="scope">
              <img :src="scope.row.avart" style="width:28px;height:28px;border-radius:4px;" alt />
            </template>
          </el-table-column>
          <el-table-column prop="admin_name" label="昵称"></el-table-column>
          <el-table-column prop="sex" label="性别"></el-table-column>
          <el-table-column prop="store" label="管理门店">
            <template slot-scope="scope">
              <span v-for="item in scope.row.store" :key="item">{{item.store_name}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="deladmin(scope.$index, tableData)"
                type="text"
                size="mini"
              >删除</el-button>
              <el-button
                @click.native.prevent="changestores(scope.$index, tableData2)"
                type="text"
                size="mini"
              >更换授权门店</el-button>
              <el-button
                @click.native.prevent="transferroles(scope.$index, tableData2)"
                type="text"
                size="mini"
              >转移成员角色</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>-->
    </el-tabs>
    <el-dialog :title="dialogTitle" :visible.sync="editrolepopup" width="50%">
      <el-form ref="formInfo" :model="formInfo" class="demo-form-inline" label-width="100px">
        <el-form-item label="角色名称" prop="rolename">
          <!-- <el-select v-model="value" style="width:98%" @change="rolechange" placeholder="请选择角色名称">
            <el-option
              v-for="(item,index) in formInfo"
              :label="item.name"
              :value="item.id"
              :key="index"
            ></el-option>
          </el-select>-->
          <el-input v-model="rolename"></el-input>
        </el-form-item>
        <div class="infoswitch" v-for="(item,index) in roleuserlist" :key="index">
          <div class="centerswitch">
            <el-switch
              v-model="item.checked"
              @change="switchbox(item)"
              :active-text="item.pc_menu_name"
              active-color="#409EFF"
              inactive-color="#DCDFE6"
            ></el-switch>
          </div>
          <div class="swit_user" v-for="(items,indexs) in item.list" :key="indexs">
            <el-switch
              class="swit_item"
              v-model="items.checked"
              :disabled="!item.checked"
              @change="switchboxs(items)"
              :active-text="items.pc_menu_name"
              active-color="#409EFF"
              inactive-color="#DCDFE6"
            ></el-switch>
            <div class="swit_usersd">
              <el-switch
                v-for="(itemes,indexes) in items.list"
                :key="indexes"
                :disabled="!items.checked"
                class="swit_item"
                v-model="itemes.checked"
                :active-text="itemes.pc_menu_name"
                active-color="#409EFF"
                inactive-color="#DCDFE6"
              ></el-switch>
            </div>
          </div>
        </div>
        <el-form-item style="text-align: right;">
          <el-button @click="editrolepopup=false">取消</el-button>
          <el-button type="primary" @click="submitForm('formInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="转移成员角色" :visible.sync="transferrolespopup" width="50%">
      <el-form
        ref="roleformInfo"
        :model="roleformInfo"
        class="demo-form-inline"
        label-width="100px"
      >
        <el-form-item label="转移至" prop="transfer">
          <el-select v-model="roleformInfo.transfer" style="width:50%" placeholder="请选择">
            <!-- <el-option label="普通座" value="1"></el-option>
            <el-option label="商务座" value="2"></el-option>
            <el-option label="豪华座" value="3"></el-option>-->
            <el-option
              :label="item.name"
              :value="item.id"
              v-for="(item,index) in activeItemList"
              :key="index"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="transferrolespopup=false">关闭</el-button>
          <el-button type="primary" @click="rolesubmitForm('roleformInfo')">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="添加成员" :visible.sync="invitepopup" width="50%">
      <el-form
        ref="inviteformInfo"
        :model="inviteformInfo"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="授权门店" prop="shop">
          <el-select
            v-model="inviteformInfo.shop"
            @change="changeadminstore"
            multiple
            style="width:50%"
            placeholder="请选择"
          >
            <el-option
              v-for="item in storelist"
              :key="item"
              :label="item.store_name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="账号" prop="username">
          <el-input v-model="inviteformInfo.username" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="inviteformInfo.password" show-password placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item label="头像" prop="avatar">
          <el-upload
            class="avatar-uploader"
            action="https://m.sapiki.com//admin/common/imageUpload"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrl" :src="imageUrl" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="invitepopup=false">关闭</el-button>
          <!-- <el-button type="primary" @click="invitesubmitForm('inviteformInfo')">生成邀请二维码</el-button> -->
          <el-button type="primary" @click="invitesubmitForm('inviteformInfo')">确定添加</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="编辑成员" :visible.sync="editMemberpopup" width="50%">
      <el-form
        ref="editformInfo"
        :model="editformInfo"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="账号" prop="admin_name">
          <el-input v-model="editformInfo.admin_name" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="password" show-password placeholder="请输入新密码"></el-input>
        </el-form-item>
        <el-form-item label="头像" prop="avatar">
          <el-upload
            class="avatar-uploader"
            action="https://m.sapiki.com//admin/common/imageUpload"
            :show-file-list="false"
            :on-success="edithandleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="upimageUrl" :src="upimageUrl" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="editMemberpopup=false">关闭</el-button>
          <el-button type="primary" @click="editsubmitForm('editformInfo')">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- <el-dialog title="邀请二维码" :visible.sync="imgpopup" width="50%" @close="closeDialog">
      <div style="text-align:center">
        <img src="../../../assets/404_images/404.png" style="width:565px;height:565px" alt />
      </div>
    </el-dialog>-->
    <el-dialog title="更换授权门店" :visible.sync="changestorespopup" width="50%">
      <el-form
        ref="changestoreformInfo"
        :model="changestoreformInfo"
        class="demo-form-inline"
        label-width="100px"
      >
        <el-form-item label="转移至" prop="storeroom">
          <el-select
            v-model="changestoreformInfo.storeroom"
            style="width:50%"
            @change="$forceUpdate()"
            multiple
            placeholder="请选择"
          >
            <el-option
              v-for="(item,index) in storemenu"
              :key="index"
              :label="item.store_name"
              :value="item.id"
            ></el-option>
            <!-- <el-option label="商务座" value="2"></el-option>
            <el-option label="豪华座" value="3"></el-option>-->
          </el-select>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="changestorespopup=false">关闭</el-button>
          <el-button type="primary" @click="changestoresubmitForm('changestoreformInfo')">保存</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  rolelist,
  edits,
  manage,
  editRole,
  manageList,
  lists,
  roledelete,
  adminAuth,
  deladmin,
  addmember,
  shiftRole,
  editMember
} from "@/api/user";
import { adminStore, adminShare } from "@/api/menu";
import Base64 from "@/utils/base";
import { getp_id } from "@/utils/getmenuid";

export default {
  inject: ["reload"],
  data() {
    return {
      formInfo: {
        rolename: "1"
      },
      rules: {
        shop: [{ required: true, message: "请选择门店", trigger: "blur" }],
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
        admin_name: [
          { required: true, message: "请输入账号", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      },
      parentcurr: "",
      avatarimg: "",
      showbtn7: false,
      showbtn4: false,
      showbtn5: false,
      showbtn19: false,
      showbtn20: false,
      showbtn21: false,
      showbtn18: true,
      editMemberpopup: false,
      rolelist: "",
      activeName: "",
      storelist: "",
      roleformInfo: {},
      inviteformInfo: {},
      editformInfo: "",
      password: "",
      changestoreformInfo: {},
      uservalue: false,
      editrolepopup: false,
      transferrolespopup: false,
      changestorespopup: false,
      invitepopup: false,
      value: "",
      imgpopup: false,
      dialogTitle: "编辑角色",
      tabPosition: "right",
      tableData: "",
      roleuserlist: "",
      id: "",
      storemenu: "",
      adminid: "",
      roleid: "",
      storeid: "",
      imageUrl: "",
      upimageUrl: "",
      totle: 10,
      page: 1,
      num: 10,
      rolename: "",
      allhttps: "https://m.sapiki.com/"
    };
  },
  mounted(){
    this.getlists(33);
    this.getmanage();
   this.getids().then((result)=>{
     this.activeName= String(result) 
    })
    // this.activeName = this.getids()
    // this.getids().then((result)=>{
    //   console.log(result)
    // })
  },
  created() {
    // this.getmanage();
    // this.getlists(33);
    // this.getmanage();
    // setTimeout(() => {
    // }, 500);
  },
  computed: {
    activeItemList() {
      return this.rolelist.filter(item => {
        return item.id != 1;
      });
    }
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = res.file_path;
    },
    edithandleAvatarSuccess(res, file) {
      this.upimageUrl = res.file_path;
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg" || file.type == "image/png";
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 或 PNG 格式!");
        return;
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
        return;
      }
    },
    getids(){
    return manage().then(res => {
        return res.result[0].id
      })
    },
    getmanage() {
      manage().then(res => {
        this.activeName = String(res.result[0].id)
        this.rolelist = res.result;
        this.roleid = String(res.result[0].id);
        this.rolename = res.result[0].name;
        this.getmanageList(String(res.result[0].id));
      });
    },
    // changestore(e) {
    //   console.log(e);
    //   this.storeid = e.join(",");
    //   console.log(this.storeid);
    // },
    //下拉授权门店
    changeadminstore(e) {},
    //删除角色
    del() {
      this.$confirm("确定删除此条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let parmes = {
            ids: this.roleid
          };
          roledelete({
            request_data: Base64.encode(JSON.stringify(parmes))
          }).then(res => {
            if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
            this.reload();
          });
        })
        .catch(() => {
         
        });
    },
    editadmin(val) {
      this.editformInfo = val;
      this.upimageUrl = val.avatar;
      this.editMemberpopup = true;
    },
    // 删除管理员
    deladmin(index, data) {
      let parmes = {
        id: data[index].id
      };
      deladmin({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.getmanageList(this.roleid);
      });
    },
    //右侧tab切换
    tabclick(val, index) {
      this.roleid = val.name;
      this.rolename = val.label;
      let parmes = {
        store_id: JSON.parse(localStorage.getItem("storemenu"))[0].id,
        admin_role_id: val.name,
        page: 1,
        limit: 10,
        p_id: getp_id()
      };
      manageList({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.tableData = res.data.data;
        this.totle = res.data.count;
      });
      // this.getlists(33)
    },
    getlists(pid) {
      lists({ request_data: Base64.encode(JSON.stringify({ pid: pid })) }).then(
        res => {
          if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
          let btnarr = [];
          res.result.map(v => {
            btnarr.push(v.class_mark);
          });
          btnarr.forEach(item => {
            if (item == "platRole_7") {
              this.showbtn7 = true;
            }
            if (item == "platRole_4") {
              this.showbtn4 = true;
            }
            if (item == "platRole_5") {
              this.showbtn5 = true;
            }
            if (item == "platRole_19") {
              this.showbtn19 = true;
            }
            if (item == "platRole_20") {
              this.showbtn20 = true;
            }
            if (item == "platRole_21") {
              this.showbtn21 = true;
            }
          });
        }
      );
    },
    getmanageList(id, page, num) {
      let parmes = {
        store_id: JSON.parse(localStorage.getItem("storemenu"))[0].id,
        admin_role_id: id,
        page: page || this.page,
        limit: num || this.num,
        p_id: getp_id()
      };
      manageList({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.tableData = res.data.data;
        this.totle = res.data.count;
      });
    },
    handleSizeChange(val) {
      this.num = val;
      this.getmanageList(this.roleid, this.page, this.num);
    },
    fenyeBtn(e) {
      this.page = e;
      this.getmanageList(this.roleid, this.page, this.num);
    },
    // rolechange(e) {
    //   this.id = e;
    // },
    submitForm() {
      let arr = [];
      let arrs = [];
      let arrss = [];
      this.roleuserlist.map(v => {
        if (v.checked == true) {
          arr.push(v.id);
        }
        v.list.map(i => {
          if (i.checked == true) {
            arrs.push(i.id);
          }
          i.list.map(s => {
            if (s.checked == true) {
              arrss.push(s.id);
            }
          });
        });
      });
      var newArr = [];
      for (var i = 0; i < arr.concat(arrs, arrss).length; i++) {
        if (newArr.indexOf(arr.concat(arrs, arrss)[i]) == -1) {
          newArr.push(arr.concat(arrs, arrss)[i]);
        }
      }
      let parems = {
        id: this.roleid,
        name: this.rolename,
        ids: newArr.join(",")
      };
      editRole({
        request_data: Base64.encode(JSON.stringify(parems))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.editrolepopup = false;
      });
    },
    rolesubmitForm() {
      let parems = {
        admin_id: this.adminid,
        role_id: this.roleformInfo.transfer
      };
      shiftRole({
        request_data: Base64.encode(JSON.stringify(parems))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.transferrolespopup = false;
        this.getmanageList(this.roleid);
      });
    },
    invitesubmitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.getaddmember();
        } else {
          return false;
        }
      });
    },
    editsubmitForm() {
      let parmes = {
        admin_id: this.editformInfo.id,
        account: this.editformInfo.admin_name,
        password: this.password,
        avatar: this.upimageUrl
      };
      editMember({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.editMemberpopup = false;
        this.getmanageList(this.roleid);
      });
    },
    // invitesubmitForm() {
    //   if(!this.inviteformInfo.shop){
    //      this.$message({
    //         type: "info",
    //         message: "请选择授权门店"
    //       })
    //       return false
    //   }
    //   this.invitepopup = false
    //   this.imgpopup = true;
    //   let parmes = {
    //     store_id:this.inviteformInfo.shop,
    //     role_id:38
    //   }
    //   adminShare(
    //     {
    //         request_data: Base64.encode(JSON.stringify({id:1}))
    //       }
    //   ).then(res => {
    //     console.log(res)
    //     this.formInfo = res.result
    //   })
    // },
    changestoresubmitForm() {
      let parmes = {
        store_id: this.changestoreformInfo.storeroom.join(","),
        admin_id: this.adminid
      };
      adminAuth({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.changestorespopup = false;
        this.getmanageList(this.roleid);
      });
    },
    // closeDialog() {
    //   this.imgpopup = false;
    //   this.invitepopup = false;
    // },
    editrole() {
      this.editrolepopup = true;
      // manage().then(res => {
      //   console.log(res);
      //   this.formInfo = res.result;
      // });
      edits({
        request_data: Base64.encode(JSON.stringify({ id: this.roleid }))
      }).then(res => {
         if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.roleuserlist = res.result;
      });
    },
    invitemembers() {
      this.invitepopup = true;
      adminStore({
        request_data: Base64.encode(JSON.stringify({ store_id: "" }))
      }).then(response => {
        if(response.status==2){
          this.$message({
            message:response.message,
            type:'warning'
          })
          return
        }
        this.storelist = response.data;
      });
    },
    //
    switchbox(e) {
      this.roleuserlist.map(v => {
        if (e.id == v.id) {
          v.list.map(i => {
            i.checked = e.checked;
            i.list.map(s => {
              s.checked = e.checked;
            });
          });
        }
      });
      // this.parentcurr = e
    },
    switchboxs(e) {
      this.roleuserlist.map(v => {
        v.list.map(i => {
          if (e.id == i.id) {
            i.list.map(s => {
              s.checked = e.checked;
            });
          }
        });
      });
    },
    getaddmember() {
      addmember({
        request_data: Base64.encode(
          JSON.stringify({
            store_id: this.inviteformInfo.shop.join(","),
            account: this.inviteformInfo.username,
            password: this.inviteformInfo.password,
            avatar: this.imageUrl,
            role_id: this.roleid
          })
        )
      }).then(res => {
         if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.invitepopup = false;
        this.getmanageList(this.roleid);
      });
    },
    //转移成员
    transferroles(index, data) {
      this.adminid = data[index].id;
      this.transferrolespopup = true;
    },
    //更换授权门店
    changestores(data) {
      this.adminid = data.id;
      adminStore({
        request_data: Base64.encode(JSON.stringify({ store_id: "" }))
      }).then(res => {
         if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        let storeid = [];
        data.store.map(i => {
          storeid.push(i.id);
        });
        this.storeid = storeid;
        this.changestoreformInfo.storeroom = storeid;
        this.changestorespopup = true;
        this.storemenu = res.data;
      });
    }
  }
};
</script>

<style scoped>
.titbox {
  width: 99%;
  height: 60px;
  background: #eeeeee;
  margin-left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 4px;
  margin-top: 0;
}
.el-table th > .cell {
  padding-left: 20px !important;
}
.el-table td {
  padding-left: 10px;
}
.role-view {
  height: calc(100vh - 80px);
  margin-top: 20px;
}
.infoswitch {
  width: 94%;
  height: auto;
  background: #ffffff;
  box-shadow: 0px 0px 10px 0px rgba(55, 55, 55, 0.17);
  border-radius: 10px;
  margin-left: 50%;
  margin-bottom: 30px;
  transform: translateX(-50%);
  overflow: hidden;
}
.centerswitch {
  margin-left: 34px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.swit_user {
  margin-left: 56px;
  /* display: flex; */
  /* align-items: center; */
  flex-wrap: wrap;
}
.swit_useruser {
  margin-left: 56px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
}
.swit_users {
  margin-left: 76px;
  margin-bottom: 20px;
}
.swit_usersd {
  margin-left: 50px;
  display: flex;
  /* margin-top: 40px; */
  /* margin-bottom:20px; */
  align-items: center;
  flex-wrap: wrap;
}
.swit_usersdsd {
  margin-left: 50px;
  display: flex;
  flex-direction: column;
  /* display: flex; */
  /* margin-top: 40px; */
  /* margin-bottom:20px; */
  /* align-items: center; */
  /* flex-wrap: wrap; */
}
.swit_item {
  margin-bottom: 20px;
  margin-right: 20px;
  margin-left: 20px;
}
.platRole_7 {
  display: none;
}
.platRole_4 {
  display: none;
}
.platRole_5 {
  display: none;
}
.platRole_15 {
  display: none;
}
.platRole_14 {
  display: none;
}
.platRole_8 {
  display: none;
}
.avatar-uploader {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 178px;
  height: 178px;
}
.avatar-uploader:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

